import { strcuture_radio } from "../CostStrategy/BaseCostStrategy";
import { PathFinderManager } from "../PathFinderManager";
import { ACostDecorate } from "./ACostDecorate";


/**
 * 普通建筑设置,会排除掉星门
 */
export class ACreepNormalStructureBlock extends ACostDecorate
{
    decorate(manager:PathFinderManager,roomName: string, costs: CostMatrix,opt:IPathFinderOpt): CostMatrix 
    {
        const room = Game.rooms[roomName]
        if(room)
        {
            // 不在我的房间.
            if(!room.IsFriend()&& opt.IsDestoryStructure)
            {
                this.setDestoryStructure(room,costs);
            }
            else 
            {
                this.setBlockStructure(room,costs);
            }
        }
        return  costs
    }


    private setBlockStructure(room:Room,costs: CostMatrix)
    {
        room.find(FIND_STRUCTURES).forEach(struct => {
            if (struct.structureType === STRUCTURE_ROAD) {
                if(costs.get(struct.pos.x, struct.pos.y)<=1)
                {
                    costs.set(struct.pos.x, struct.pos.y, 1)
                }
                
            }
            // 不能穿过无法行走的建筑
            else if (struct.structureType !== STRUCTURE_CONTAINER &&
                (struct.structureType !== STRUCTURE_RAMPART || !struct.my)
            )
            {
                costs.set(struct.pos.x, struct.pos.y, 0xff)
            }
            
        })
    }

    private setDestoryStructure(room:Room,costs: CostMatrix)
    {
        room.find(FIND_STRUCTURES).forEach(struct => {
            if (struct.structureType === STRUCTURE_ROAD) {
                if(costs.get(struct.pos.x, struct.pos.y)<=1)
                {
                    costs.set(struct.pos.x, struct.pos.y, 1)
                }
                
            }
            // 不能穿过无法行走的建筑
            else  
            {
                
                {
                    const cost = Math.round( struct.hits*strcuture_radio )+5;
                    if(costs.get(struct.pos.x, struct.pos.y)< cost)
                    {
                        costs.set(struct.pos.x, struct.pos.y, cost)
                    }
                }
                
            }
            
        })
    }
}